<template>
  <div>
    <FormPanel  
      ref="from"
      :list="initForm"
      :cols="3"
      :formType="value.type"
      :labelWidth="120"
      :isSubmitBtn="false"
      :collapse="false"
      @formChange="changeHandle"
    />
    <div
      :style="{
        textAlign: 'center'
      }"
    >
      <el-button :loading="loadingFlag" @click="saveDialog()" type="primary">保 存</el-button>
      <el-button @click="closeDialog('closeDialog')">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { postSaveCk } from '@/api/partsmanage/claim/apply';
import moment from 'moment';
export default {
  name: 'chaimwarehouseinfo',
  props:{
    value: {
      type: Object,
      data: Object,
      required: true,
      claimid: ''
    },
  },
  data() {
    this.saveData=null;
    return {
      type: this.value.type,
      initForm : this.initFormFun(),
      loadingFlag: false
    };
  },
  created() {
    this.init(this.value.data)
  },
  methods: {
    init(data) {
      this.claimid = data.id
    },
    //取消操作
    closeDialog(type) {
      this.$emit('close', {visible: false, type: type});
    },
    initFormFun(){
      return [
        {
          selfCols: 3,
          type: 'UPLOAD_FILE',
          label: '上传文件',
          fieldName: 'ckFiles',
          placeholder: '上传文件...',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 2,
            tipText: '（支持：PDF、RAR、JPG格式）'
          }
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'bsckcl',
          placeholder: '请输入',
          selfCols:3,
          rules: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }]
        },
      ]
    },
    changeHandle(val){
      this.saveData=val
    },
    async saveDialog() {
      this.$refs.from.SUBMIT_FORM();
      if (this.saveData) {
        this.loadingFlag = true;
        this.saveData.id = this.claimid
        let res=await postSaveCk(this.saveData)
        if (res.resultCode === 200) {
          this.$notify.success({title: '提示信息',message:'保存成功!'});
          this.loadingFlag = false;
          this.closeDialog('refresh')
        } else {
          this.$notify.error({title: '提示信息',message:res.errMsg||'保存失败!'});
        }
      }
    }
  }
};
</script>
<style scoped>
.wrapper {
  height: calc(100vh - 110px);
}
</style>